package com.coupon.gui;

import javax.faces.application.FacesMessage;
import javax.faces.context.FacesContext;

import org.springframework.beans.factory.annotation.Required;

import com.coupon.bl.CouponException;
import com.coupon.bl.UserHandler;
import com.coupon.dal.entity.User;


public class LoginBean {
	
	private UserHandler userHandler=null;
	private String email;
	
	
	public String addUser(){
		User userEntity = new User(getEmail());
		try {
			userHandler.addUser(userEntity);
			return "success";
		} catch (CouponException e) {
			FacesContext context = FacesContext.getCurrentInstance();
			FacesMessage message = new FacesMessage();
			message.setSeverity(FacesMessage.SEVERITY_INFO);
			message.setSummary(e.getMessage());
			context.addMessage(null, message); 
			return "failed";
		}
	}
	
	
	@Required
	public void setUserHandler(UserHandler userHandler) {
		this.userHandler = userHandler;
	}


	public String getEmail() {
		return email;
	}


	public void setEmail(String email) {
		this.email = email;
	}
	
	

}
